package com.gxa.finance.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.commons.R;
import com.gxa.finance.mapper.ServiceDetailsMapper;
import com.gxa.common.pojo.ServiceDetails;
import com.gxa.finance.service.ServiceDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServiceDetailsServiceImpl extends ServiceImpl<ServiceDetailsMapper, ServiceDetails> implements ServiceDetailsService {

    @Autowired
    private ServiceDetailsMapper serviceDetailsMapper;

    //查询接口
    @Override
    public R findServiceDetailsList(String serve,Integer price) {
        R r = new R();
        try{
            List<ServiceDetails> serviceDetailsList = serviceDetailsMapper.findServiceDetailsList(serve,price);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(serviceDetailsList);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("网络开小差");
        }
        return r;
    }

    //新增接口
    @Override
    public R addServiceDetails(ServiceDetails serviceDetails) {
        R r = new R();
        int result = serviceDetailsMapper.insert(serviceDetails);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }

    @Override
    public R delServiceDetails(Integer id) {

        R r = new R();
        int result = serviceDetailsMapper.deleteById(id);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("删除成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;

    }

    @Override
    public R updateServiceDetails(ServiceDetails serviceDetails) {
        R r = new R();
        int result = serviceDetailsMapper.updateById(serviceDetails);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }
}
